// /////////////////////////////////////////////////////////////////////////////
//
// Name:            SoundProcessor.h
// Author:          Michael Bartsch (ZCCdark203)
//
// Desc :           Declaration of the SoundProcessor class.
//
// License:         Copyright (C) 2009 Michael Bartsch and Contributors
//
//                  This program is free software: you can redistribute it
//                  and/or modify it under the terms of the zlib/libpng License.
//                  See main.cpp for conditions of distribution and use.
//
// /////////////////////////////////////////////////////////////////////////////

#ifndef __SOUNDPROCESSOR_H__
#define __SOUNDPROCESSOR_H__

// Include files
#include "../dependencies.h"

#ifdef __COMPILE_WITH_SFML_AUDIO__

#include "../core/AssetProcessor.h"


// SoundProcessor class
//! AssetProcessor for processing sounds in an AssetGroup.
//! In order to properly reload a sound from an asset group the class that uses the sound
//! needs to implement a event method for the "sounds/<filename>" event. When the sound
//! is reloaded a event will be emitted to the appropriate slot with the new sound as the
//! parameter. See SoundSourceComponent::onSound for an example.
class SoundProcessor : public AssetProcessor
{
public:

    // Initialisation and deinitialisation
    //! Constructor
    SoundProcessor(AssetGroup *parent);
    //! Deconstructor
    ~SoundProcessor();

    // Public methods
    //! Gets the sound with the given filename as memory.
    //! @param fileName      Filename of the sound.
    //! @param buffer        A pointer to the start of the sound buffer.
    //! @param length        Length of the buffer.
    //! @return True on success, false on failure.
    bool getSound(const std::string &fileName, c8 *& buffer, long &length);

    //! Reloads the asset with the given filename.
    //! @param fileName      Filename of the asset.
    //! @return True on succesful removal, false otherwise.
    bool reloadAsset(const std::string &fileName);
    //! Reloads all assets.
    void reloadAssets();

    //! Removes the asset with the given filename.
    //! @param fileName      Filename of the asset.
    //! @return True on succesful removal, false otherwise.
    bool removeAsset(const std::string &fileName) ;
    //! Removes all assets.
    void removeAssets();

    //! Creates a new SoundProcessor.
    //! @note For internal use only!
    static AssetProcessor* createProcessor(AssetGroup *parent);

protected:

    // Protected methods
    //! Loads the asset with the given filename.
    //! @param fileName      Filename of the asset.
    //! @return True on succesful loading, false otherwise.
    bool loadAsset(const std::string &fileName);
    //! Loads all assets.
    void loadAssets();


private:

    // Private members
    std::map<std::string, std::pair<c8*, long> > mSounds;

    bool mIsReloading;
};

#endif // __COMPILE_WITH_SFML_AUDIO__

#endif
